home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 February / Macworld (1999-02).dmg / Serious Demos / Portfolio 4.0.1 / Scripting Extras / Background Cataloger.txt next >
Text File  |  1998-09-15  |  3KB  |  78 lines

  1. -- Some basic properties for the cataloger.
  2. -- Enter values in the fPath and catPath variables to have Background Cataloging automatically
  3. --    monitor these paths, or leave them blank to be prompted at start-up.
  4.  
  5. property fPath : "" -- Path to the folder to monitor
  6. property catPath : "" -- Path to the catalog to add to
  7. property lastMod : date "Monday, January 1, 1900 12:00:00 AM" -- Date the folder was last modified. Start with an arbitrarily old date.
  8. property intvl : 10 -- Interval, in minutes, between checking the folder for changes.
  9.  
  10.  
  11.  
  12.  
  13. --Upon launch, get the information about what will be monitored.
  14. on run
  15.     setup()
  16. end run
  17.  
  18.  
  19. -- The idle loop is the center of the process. 
  20. --Every intvl seconds, check to see if the folder has changed.
  21. on idle
  22.     tell application "Portfolio"
  23.         if is cataloging then
  24.             return 5 -- If Portfolio is busy cataloging, then wait five seconds and try again
  25.         else
  26.             tell me
  27.                 watch()
  28.             end tell
  29.         end if
  30.     end tell
  31.     return (intvl * 60)
  32. end idle
  33.  
  34. ---
  35.  
  36. -- Setup is where the user is prompted for the paths to the catalog and folder.
  37. --    We've included handlers to allow for keeping same values from previous use (dfeather, 8/23/98)
  38. -- Alternately, these values could be hardcoded for unattended launches.
  39.  
  40.  
  41. on setup()
  42.     if catPath = "" then
  43.         set catPath to choose file with prompt "Select the catalog to add to:" of type {"DBSE"}
  44.     else
  45.         set ddial to (display dialog "Do you want to continue adding to the catalog: “" & catPath & "” " buttons {"Yes", "Select another…"} default button 1)
  46.         if button returned of ddial is not "Yes" then
  47.             set catPath to choose file with prompt "Select the catalog to add to:" of type {"DBSE"}
  48.         end if
  49.     end if
  50.     if fPath = "" then
  51.         set fPath to choose folder with prompt "Select the folder to monitor:"
  52.     else
  53.         set ddial to (display dialog "Do you want to continue monitoring the folder: “" & fPath & "” " buttons {"Yes", "Select another…"} default button 1)
  54.         if button returned of ddial is not "Yes" then
  55.             set fPath to choose folder with prompt "Select the folder to monitor:"
  56.         end if
  57.     end if
  58.     set x to text returned of (display dialog "How many minutes between folder checks?" default answer "10")
  59.     --if x as real is ((integer) is true) then 
  60.     set intvl to x
  61. end setup
  62.  
  63. on watch()
  64.     tell application "Finder"
  65.         update fPath
  66.         set fPath to fPath as alias
  67.         set modDate to modification date obsolete of alias (fPath as text)
  68.         if modDate > lastMod then
  69.             set lastMod to modDate
  70.             tell application "Portfolio"
  71.                 open catPath
  72.                 catalog alias (fPath as string) to front gallery
  73.             end tell
  74.         end if
  75.     end tell
  76.     return
  77. end watch
  78.